package com.qf.shop.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description
 * @Author dearkzid
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2021/8/10
 */
@Configuration
public class ESConfig {

    @Value("${es.host}")
    private String host;

    @Value("${es.port}")
    private Integer port;

    @Bean
    public RestHighLevelClient client(){
        //1.设置es的ip和端口
        HttpHost httpHost = new HttpHost(host,port);
        //2.把HttpHost对象封装在RestClientBuilder
        RestClientBuilder restClientBuilder = RestClient.builder(httpHost);
        //3.把RestClientBuilder对象封装在RestHighLevelClient
        RestHighLevelClient client =new RestHighLevelClient(restClientBuilder);
        //4.返回
        return client;
    }
}
